//////////////////////////////////////
// Fast Container Library           //
// MIT License - Copyright (c) 2012 //
//////////////////////////////////////

#pragma once

#include "parallel.h"
#include "fixed_vector_set.h"


FC_NAMESPACE_BEGIN

template <class T, size_t N, class ParallelContainer, class Allocator>
class fixed_parallel : public parallel<T, ParallelContainer, Allocator>
{
public:
	typedef fixed_parallel<T, N, ParallelContainer, Allocator>	this_type;
	typedef parallel<T, ParallelContainer, Allocator>			base_type;
	typedef typename base_type::cell_type						cell_type;
	typedef typename base_type::pointer							pointer;
	typedef typename base_type::size_type						size_type;

	using base_type::m_allocator;
	using base_type::m_begin;
	using base_type::m_end;
	using base_type::m_capacity;

	typedef aligned_buffer<N * sizeof(T), FC_ALIGNOF(T)> buffer_type;

	fixed_parallel()
		: base_type()
		{
			init();
		}

	explicit fixed_parallel( size_t n, const T& value = T() )
		: base_type()
		{
			init();
			base_type::resize(n, value);
		}

	template<class Iter>
		fixed_parallel( Iter first, Iter last )
		: base_type()
		{
			init();
			base_type::assign( first, last );
		}

	fixed_parallel( const this_type& x )
		: base_type()
		{
			init();
			*this = x;
		}

	this_type& operator =( const this_type& x )
	{
		base_type::operator =(x);
		return *this;
	}

	bool has_overflowed() const
	{
		return m_begin != get_buffer();
	}

	void reset()
	{
		if( m_capacity )
			base_type::set_capacity(0);

		init();
	}

	void init()
	{
		m_begin = m_end = (T*)m_buffer.data;
		m_capacity = m_begin + N;
		m_allocator.set_buffer(m_begin);
	}

	pointer get_buffer() const
	{
		return (pointer)m_buffer.data;
	}

protected:
	buffer_type m_buffer;

};



FC_NAMESPACE_END
